﻿Imports System.Windows.Forms
Imports System.IO


Public Class SettingsPage
    Inherits baseForm
    Private folderName As String
    Dim namafile As String

    Private Sub btnSimpanProfil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpanProfil.Click
        If Utils.exec_SP("proc_master_profil", New Object() {"edit", TextNamaProfil.Text, TextAlamatProfil.Text, TextTelponProfil.Text, TextFaxProfil.Text}) Then
            MessageBox.Show("Data berhasil disimpan.")
            Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_master_profil|edit", TextNamaProfil.Text, Session.username})
            'RefreshTableAgama()
            RefreshTableProfil()
            Dim dtN As New DataTable
            If Utils.executeSP("proc_master_profil", New Object() {"select", Convert.DBNull, Convert.DBNull, Convert.DBNull, Convert.DBNull}, dtN) Then
                If dtN IsNot Nothing Then
                    If dtN.Rows.Count > 0 Then
                        Session.vcompany = dtN.Rows(0)("nama")
                        Session.valamat = dtN.Rows(0)("alamat")
                        Session.vtelepon = dtN.Rows(0)("telepon")
                        Session.vfax = dtN.Rows(0)("fax")
                    Else
                        Session.vcompany = ""
                        Session.valamat = ""
                        Session.vtelepon = ""
                        Session.vfax = ""
                    End If
                Else
                    Session.vcompany = ""
                    Session.valamat = ""
                    Session.vtelepon = ""
                    Session.vfax = ""
                End If
            End If

        Else
            MessageBox.Show("Data gagal disimpan.")
        End If
    End Sub
    Private Function ValidasiAgama() As String
        If TextNamaAgama.Text = "" Then
            Return "Nama agama masih kosong."
        End If
        Return "Success"
    End Function
    Private Sub btnAddAgama_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddAgama.Click
        If btnAddAgama.Text = "Add" Then
            btnDelAgama.Enabled = False
            btnEditAgama.Enabled = False
            DGVagama.Enabled = False
            'TextKodeAgama.Enabled = True
            TextNamaAgama.Enabled = True
            TextNamaAgama.Text = ""
            btnAddAgama.Text = "Save"
            TextNamaAgama.Focus()
        Else
            Dim res As String = ValidasiAgama()
            If res = "Success" Then
                If Utils.exec_SP("proc_master_agama", New Object() {"add", "0", TextNamaAgama.Text}) Then
                    MessageBox.Show("Data berhasil ditambahkan.")
                    Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_master_agama|add", TextNamaAgama.Text, Session.username})
                    'RefreshTableAgama()
                Else
                    MessageBox.Show("Data gagal ditambahkan.")
                    TextKodeAgama.Text = ""
                    TextNamaAgama.Text = ""
                End If
            Else
                MessageBox.Show(res, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            End If
            RefreshTableAgama()
            btnAddAgama.Text = "Add"
            btnDelAgama.Enabled = True
            btnEditAgama.Enabled = True
            DGVagama.Enabled = True
            TextKodeAgama.Enabled = False
            TextNamaAgama.Enabled = False
        End If
    End Sub
    Public Sub RefreshTableAgama()
        Dim dt As New DataTable
        'Dim dsrole As New DataSet
        If Utils.executeSP("proc_master_agama", New Object() {"select", "0", "0"}, dt) Then
            If dt IsNot Nothing Then
                DGVagama.DataSource = dt
            End If
        End If
    End Sub

    Private Sub btnEditAgama_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditAgama.Click
        If btnEditAgama.Text = "Edit" Then
            btnDelAgama.Enabled = False
            btnAddAgama.Enabled = False
            'TextKode.Enabled = True
            TextNamaAgama.Enabled = True
            btnEditAgama.Text = "Update"
            TextNamaAgama.Focus()
        Else
            btnEditAgama.Text = "Edit"
            btnDelAgama.Enabled = True
            btnAddAgama.Enabled = True
            TextKodeAgama.Enabled = False
            TextNamaAgama.Enabled = False
            If Utils.exec_SP("proc_master_agama", New Object() {"edit", TextKodeAgama.Text, TextNamaAgama.Text}) Then
                MessageBox.Show("Data berhasil diupdate.")
                Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_master_agama|edit", TextNamaAgama.Text, Session.username})
                'RefreshTableAgama()
            Else
                MessageBox.Show("Data gagal diupdate.")
            End If
            RefreshTableAgama()
        End If
    End Sub

    Private Sub btnDelAgama_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelAgama.Click
        If TextKodeAgama.Text = "" Then
            MessageBox.Show("Pilih Data Yang ingin dihapus", "Pesan Error", MessageBoxButtons.OK)
        Else
            Dim retval As Integer = MessageBox.Show("Apakah anda yakin akan menghapus " & TextKodeAgama.Text & " - " & TextNamaAgama.Text & " ?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
            If retval = DialogResult.Yes Then

                If Utils.exec_SP("proc_master_agama", New Object() {"delete", TextKodeAgama.Text, TextNamaAgama.Text}) Then
                    MessageBox.Show("Data berhasil dihapus.")
                    Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_master_agama|delete", TextNamaAgama.Text, Session.username})
                    RefreshTableAgama()
                Else
                    MessageBox.Show("Data gagal dihapus.")
                End If
                TextKodeAgama.Text = ""
                TextNamaAgama.Text = ""
            End If
            RefreshTableAgama()
        End If
    End Sub
    Private Function ValidasiRole() As String
        If TextKodeRole.Text = "" Then
            Return "Kode masih kosong."
        End If
        Return "Success"
    End Function
    Private Sub btnAddRole_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddRole.Click
        If btnAddRole.Text = "Add" Then
            btnDelRole.Enabled = False
            btnEditRole.Enabled = False
            DGVRole.Enabled = False
            PanelRole.Enabled = True
            TextKodeRole.Text = ""
            TextRole.Text = ""
            btnAddRole.Text = "Save"
            TextKodeRole.Focus()
        Else
            Dim res As String = ValidasiRole()
            If res = "Success" Then
                Dim dt As New DataTable
                If Utils.executeSP("proc_jabatan", New Object() {"add", TextKodeRole.Text, TextRole.Text}, dt) Then
                    If dt IsNot Nothing Then
                        MessageBox.Show(dt.Rows(0)("pesan").ToString)
                        Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_jabatan|add", TextKodeRole.Text, Session.username})
                    End If
                End If
            Else
                MessageBox.Show(res, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            End If
            RefreshTableRole()
            btnAddRole.Text = "Add"
            btnDelRole.Enabled = True
            btnEditRole.Enabled = True
            DGVRole.Enabled = True
            PanelRole.Enabled = False
            RefreshComPetugas()
        End If
    End Sub
    Public Sub RefreshComPetugas()
        Dim dt As New DataTable
        If Utils.executeSP("proc_jabatan", New Object() {"select", TextKodeRole.Text, TextRole.Text}, dt) Then
            If dt IsNot Nothing Then
                ComRolePetugas.DataSource = dt
                ComRolePetugas.DisplayMember = "role"
                ComRolePetugas.ValueMember = "koderole"
                'ComRolePetugas.Text = ""
                If ComRolePetugas.SelectedIndex = -1 Then ComRolePetugas.SelectedIndex = 0
            End If
            'TextBiayaPeriksa.Text = ComJenisPenyakit.SelectedValue
        End If
    End Sub
    Public Sub RefreshTableRole()
        Dim dt As New DataTable
        'Dim dsrole As New DataSet
        If Utils.executeSP("proc_jabatan", New Object() {"select", TextKodeRole.Text, TextRole.Text}, dt) Then
            If dt IsNot Nothing Then
                DGVRole.DataSource = dt
            End If
        End If
    End Sub

    Private Sub btnEditRole_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditRole.Click
        If btnEditRole.Text = "Edit" Then
            btnDelRole.Enabled = False
            btnAddRole.Enabled = False
            'TextKode.Enabled = True
            PanelRole.Enabled = True
            btnEditRole.Text = "Update"
            TextKodeRole.Focus()
        Else
            btnEditRole.Text = "Edit"
            btnDelRole.Enabled = True
            btnAddRole.Enabled = True
            PanelRole.Enabled = False
            Dim dt As New DataTable
            If Utils.executeSP("proc_jabatan", New Object() {"edit", TextKodeRole.Text, TextRole.Text}, dt) Then
                If dt IsNot Nothing Then
                    MessageBox.Show(dt.Rows(0)("pesan").ToString)
                    Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_jabatan|edit", TextKodeRole.Text, Session.username})
                End If
            End If
            RefreshTableRole()
        End If
        RefreshComPetugas()
    End Sub

    Private Sub btnDelRole_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelRole.Click
        If TextKodeRole.Text = "" Then
            MessageBox.Show("Pilih Data Yang ingin dihapus", "Pesan Error", MessageBoxButtons.OK)
        Else
            Dim retval As Integer = MessageBox.Show("Apakah anda yakin akan menghapus " & TextKodeRole.Text & " ?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
            If retval = DialogResult.Yes Then
                Dim dt As New DataTable
                If Utils.executeSP("proc_jabatan", New Object() {"delete", TextKodeRole.Text, TextRole.Text}, dt) Then
                    If dt IsNot Nothing Then
                        MessageBox.Show(dt.Rows(0)("pesan").ToString)
                        Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_jabatan|delete", TextKodeRole.Text, Session.username})
                    End If
                End If
            End If
            RefreshTableRole()
        End If
    End Sub
    Private Function ValidasiPetugas() As String
        If TextUsernamePetugas.Text = "" Then
            Return "Username masih kosong."
        End If
        Return "Success"
    End Function
    Public Sub RefreshTablePetugas()
        Dim dt As New DataTable
        'Dim dsrole As New DataSet
        If Utils.executeSP("proc_petugas", New Object() {"select", TextUsernamePetugas.Text, TextPassPetugas.Text, TextNamaPetugas.Text, TextKodeRolePetugas.Text, TextAlamatPetugas.Text, TextHPPetugas.Text}, dt) Then
            If dt IsNot Nothing Then
                DGVPetugas.DataSource = dt
            End If
        End If
    End Sub
    Private Sub btnAddPetugas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddPetugas.Click
        If btnAddPetugas.Text = "Add" Then
            btnDelPetugas.Enabled = False
            btnEditPetugas.Enabled = False
            DGVPetugas.Enabled = False
            PanelPetugas.Enabled = True
            TextUsernamePetugas.Text = ""
            TextPassPetugas.Text = ""
            TextNamaPetugas.Text = ""
            'ComRolePetugas.Text = ""
            'TextKodeRolePetugas.Text = 0
            TextHPPetugas.Text = ""
            TextAlamatPetugas.Text = ""
            btnAddPetugas.Text = "Save"
            TextUsernamePetugas.Focus()
        Else
            Dim res As String = ValidasiPetugas()
            If res = "Success" Then
                Dim dt As New DataTable
                If Utils.executeSP("proc_petugas", New Object() {"add", TextUsernamePetugas.Text, TextPassPetugas.Text, TextNamaPetugas.Text, ComRolePetugas.SelectedValue, TextAlamatPetugas.Text, TextHPPetugas.Text}, dt) Then
                    If dt IsNot Nothing Then
                        MessageBox.Show(dt.Rows(0)("pesan").ToString)
                        Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_petugas|add", TextUsernamePetugas.Text, Session.username})
                    End If
                End If
            Else
                MessageBox.Show(res, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            End If
            RefreshTablePetugas()
            btnAddPetugas.Text = "Add"
            btnDelPetugas.Enabled = True
            btnEditPetugas.Enabled = True
            DGVPetugas.Enabled = True
            PanelPetugas.Enabled = False
        End If
    End Sub

    Private Sub btnEditPetugas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditPetugas.Click
        If btnEditPetugas.Text = "Edit" Then
            btnDelPetugas.Enabled = False
            btnAddPetugas.Enabled = False
            'TextKode.Enabled = True
            PanelPetugas.Enabled = True
            btnEditPetugas.Text = "Update"
            TextPassPetugas.Focus()
        Else
            btnEditPetugas.Text = "Edit"
            btnDelPetugas.Enabled = True
            btnAddPetugas.Enabled = True
            PanelPetugas.Enabled = False
            Dim dt As New DataTable
            If Utils.executeSP("proc_petugas", New Object() {"edit", TextUsernamePetugas.Text, TextPassPetugas.Text, TextNamaPetugas.Text, ComRolePetugas.SelectedValue, TextAlamatPetugas.Text, TextHPPetugas.Text}, dt) Then
                If dt IsNot Nothing Then
                    MessageBox.Show(dt.Rows(0)("pesan").ToString)
                    Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_petugas|edit", TextUsernamePetugas.Text, Session.username})
                End If
            End If
            RefreshTablePetugas()
        End If
    End Sub

    Private Sub btnDelPetugas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelPetugas.Click
        If TextUsernamePetugas.Text = "" Then
            MessageBox.Show("Pilih Data Yang ingin dihapus", "Pesan Error", MessageBoxButtons.OK)
        Else
            Dim retval As Integer = MessageBox.Show("Apakah anda yakin akan menghapus " & TextUsernamePetugas.Text & " ?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
            If retval = DialogResult.Yes Then
                Dim dt As New DataTable
                If Utils.executeSP("proc_petugas", New Object() {"delete", TextUsernamePetugas.Text, TextPassPetugas.Text, TextNamaPetugas.Text, TextKodeRolePetugas.Text, TextAlamatPetugas.Text, TextHPPetugas.Text}, dt) Then
                    If dt IsNot Nothing Then
                        MessageBox.Show(dt.Rows(0)("pesan").ToString)
                        Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_petugas|delete", TextUsernamePetugas.Text, Session.username})
                    End If
                End If

            End If
            RefreshTablePetugas()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If (TextDatabase.Text = "") Or (TextHost.Text = "") Or (TextUsername.Text = "") Or (TextPort.Text = "") Then
            MessageBox.Show("Maaf Silahkan Lengkapi Database Setting anda !", "Get MySql Connection")
            Exit Sub
        End If
        Dim result As DialogResult = folderBrowse.ShowDialog()
        If (result = Windows.Forms.DialogResult.OK) Then
            folderName = folderBrowse.SelectedPath
            If Microsoft.VisualBasic.Right(folderName, 1) = "\" Then
                LblPath.Text = folderName & TextDatabase.Text & Replace(Now.Date, "/", "") & ".sql"
            Else
                LblPath.Text = folderName & "\" & TextDatabase.Text & Replace(Now.Date, "/", "") & ".sql"
            End If
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim errmsg As String = ""
        If Not Utils.testkoneksi(errmsg, New Object() {TextDatabase.Text, _
                                       TextHost.Text, _
                                       TextUsername.Text, _
                                       TextPassword.Text, _
                                       TextPort.Text}) Then



            MessageBox.Show("Error Tes Koneksi" & vbCrLf & errmsg, "Tes Koneksi")
            Exit Sub
        End If

        If LblPath.Text = "" Then
            MessageBox.Show("Folder Location Not Complete", "Checking Folder")
            Exit Sub
        End If

        If Backup(errmsg) Then
            MessageBox.Show("Proses Backup selesai " & vbCrLf & "File Location = " & LblPath.Text, "Backup Proses")
        Else
            MessageBox.Show("Proses Backup Terminate " & vbCrLf & errmsg, "Backup Proses")

        End If
    End Sub
    Private Function Backup(ByRef errmsg As String) As Boolean
        Try
            If File.Exists(LblPath.Text) Then
                File.Delete(LblPath.Text)
            End If

            If TextPassword.Text = "" Then
                'Process.Start(Application.StartupPath & "\mysqldump.exe", "--user=" & TextUsername.Text & " --host=" & TextHost.Text & " -B -C -R " & TextDatabase.Text & " > -r """ & LblPath.Text & """")
                Process.Start(Application.StartupPath & "\mysqldump.exe", "--user=" & TextUsername.Text & " --host=" & TextHost.Text & " --databases --opt -C -R " & TextDatabase.Text & " -r """ & LblPath.Text & """")
                'System.Threading.Thread.Sleep(2000)
            Else
                Process.Start(Application.StartupPath & "\mysqldump.exe", "--user=" & TextUsername.Text & " --password=" & TextPassword.Text & " --host=" & TextHost.Text & " -B -C -R " & TextDatabase.Text & " -r """ & LblPath.Text & """")
                'System.Threading.Thread.Sleep(2000)
            End If

            Return True

        Catch ex As Exception
            errmsg = ex.Message
            Return False
        End Try
    End Function

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If (TextHost.Text = "") Or (TextUsername.Text = "") Or (TextPort.Text = "") Then
            MessageBox.Show("Maaf Silahkan Lengkapi Database Setting anda !", "Get MySql Connection")
            Exit Sub
        End If
        OpenFileDialog1.Filter = "SQL files (*.sql)|*.SQL"

        OpenFileDialog1.FilterIndex = 2
        OpenFileDialog1.RestoreDirectory = True
        OpenFileDialog1.FileName = ""
        If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            TextBox1.Text = OpenFileDialog1.FileName

        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim errmsg As String = ""
        Dim tujuan As String
        If Not Utils.testkoneksi(errmsg, New Object() {"mysql", _
                                       TextHost.Text, _
                                       TextUsername.Text, _
                                       TextPassword.Text, _
                                       TextPort.Text}) Then



            MessageBox.Show("Error Tes Koneksi" & vbCrLf & errmsg, "Tes Koneksi")
            Exit Sub
        End If
        If TextBox1.Text = "" Then
            MessageBox.Show("Source File Location Not Complete", "Checking File")
            Exit Sub
        End If

        Try

            Dim fs As New FileStream(Application.StartupPath & "\tempFile.bat", FileMode.Create, FileAccess.Write)
            Dim s As New StreamWriter(fs)
            s.BaseStream.Seek(0, SeekOrigin.End)
            s.WriteLine("@echo off")

            If File.Exists(TextBox1.Text) Then
                Me.Cursor = Cursors.WaitCursor
                tujuan = "D:\tempback.sql"
                File.Copy(TextBox1.Text, tujuan, True)
                If TextPassword.Text = "" Then
                    s.WriteLine("mysql --user=" & TextUsername.Text & " --host=" & TextHost.Text & " mysql < " & tujuan)
                    s.Close()

                    ShellandWait(Application.StartupPath & "\tempFile.bat", tujuan)

                Else
                    s.WriteLine("mysql --user=" & TextUsername.Text & " --password=" & TextPassword.Text & " --host=" & TextHost.Text & " mysql < " & tujuan)
                    s.Close()

                    ShellandWait(Application.StartupPath & "\tempFile.bat", tujuan)
                End If
                Me.Cursor = Cursors.Default
            Else
                MessageBox.Show("Proses Restore Terminate File Not Found", "Restore Proses")
            End If

        Catch ex As Exception
            errmsg = ex.Message
            MessageBox.Show("Proses Restore Terminate File Not Found" & vbCrLf & errmsg, "Restore Proses")
        End Try
    End Sub
    Public Sub ShellandWait(ByVal ProcessPath As String, ByVal executescript As String)
        Dim objProcess As System.Diagnostics.Process
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = ProcessPath
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objProcess.Start()

            'Wait until the process passes back an exit code 
            objProcess.WaitForExit()

            'Free resources associated with this process
            objProcess.Close()
            MessageBox.Show("Proses Restore selesai ", "Restore Proses")
            File.Delete(executescript)
        Catch
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Try
    End Sub

    Private Sub SettingsPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RefreshTableAgama()
        RefreshTablePetugas()
        RefreshTableProfil()
        RefreshTableRole()
        RefreshComPetugas()

        FillFormByRegistry()
    End Sub
    Public Sub RefreshTableProfil()
        Dim dt As New DataTable
        'Dim dsrole As New DataSet
        If Utils.executeSP("proc_master_profil", New Object() {"select", "0", "0", "0", "0"}, dt) Then
            If dt IsNot Nothing Then
                'DGVagama.DataSource = ds.Tables(0)
                TextNamaProfil.Text = dt.Rows(0)(0)
                TextAlamatProfil.Text = dt.Rows(0)(1)
                TextTelponProfil.Text = dt.Rows(0)(2)
                TextFaxProfil.Text = dt.Rows(0)(3)
            End If
        End If
    End Sub

    Private Sub FillFormByRegistry()
        Dim database As String = My.Settings.dbname
        Dim host As String = My.Settings.dbhost
        Dim port As String = My.Settings.dbport
        Dim username As String = My.Settings.dbuser
        Dim password As String = My.Settings.dbpassword

        If Not database Is Nothing Then
            TextDatabase.Text = database
        Else
            TextDatabase.Text = ""
        End If
        If Not host Is Nothing Then
            TextHost.Text = host
        Else
            TextHost.Text = ""
        End If
        If Not port Is Nothing Then
            TextPort.Text = port
        Else
            TextPort.Text = "3306"
        End If
        If Not username Is Nothing Then
            TextUsername.Text = username
        Else
            TextUsername.Text = ""
        End If
        If Not password Is Nothing Then
            TextPassword.Text = password
        Else
            TextPassword.Text = ""
        End If
    End Sub

    Private Sub DGVagama_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVagama.CellClick
        If e.RowIndex = -1 Then Exit Sub
        TextKodeAgama.Text = DGVagama.CurrentRow.Cells(0).Value.ToString
        TextNamaAgama.Text = DGVagama.CurrentRow.Cells(1).Value.ToString
    End Sub

    Private Sub DGVRole_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVRole.CellClick
        If e.RowIndex = -1 Then Exit Sub
    End Sub

    Private Sub DGVPetugas_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DGVPetugas.SelectionChanged
        With DGVPetugas
            Try
                TextUsernamePetugas.Text = .CurrentRow.Cells(0).Value.ToString
                TextPassPetugas.Text = .CurrentRow.Cells(1).Value.ToString
                TextNamaPetugas.Text = .CurrentRow.Cells(2).Value.ToString
                ComRolePetugas.Text = .CurrentRow.Cells(3).Value.ToString
                TextKodeRolePetugas.Text = .CurrentRow.Cells(4).Value.ToString
                TextAlamatPetugas.Text = .CurrentRow.Cells(5).Value.ToString
                TextHPPetugas.Text = .CurrentRow.Cells(6).Value.ToString
            Catch

            End Try
        End With
    End Sub

    Private Sub DGVRole_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DGVRole.SelectionChanged
        'MsgBox(DGVRole.CurrentRow.Index)

        With DGVRole
            Try
                TextKodeRole.Text = .CurrentRow.Cells(0).Value.ToString
                TextRole.Text = .CurrentRow.Cells(1).Value.ToString
            Catch ex As Exception

            End Try
           
        End With
    End Sub
End Class
